var dtime = '_deadtime';
export function cacheSet(k, v, t) {
  uni.setStorageSync(k, v)
  var day = parseInt(t);
  if (day > 0) {
    var timestamp = Date.parse(new Date());
    timestamp = timestamp / 1000*3600*24 + day;
    uni.setStorageSync(k + dtime, timestamp + "")
  } else {
    uni.removeStorageSync(k + dtime)
  }
}

export function cacheGet(k, def) {
  var deadtime = parseInt(uni.getStorageSync(k + dtime))
  if (deadtime) {
    if (parseInt(deadtime) < Date.parse(new Date())/(1000*3600*24)) {
      if (def) { return def; } else { return; }
    }
  }
  var res = uni.getStorageSync(k);
  if (res) {
    return res;
  } else {
    return def;
  }
}

export function cacheRemove(k) {
  uni.removeStorageSync(k);
  uni.removeStorageSync(k + dtime);
}

export function cacheClear() {
  uni.clearStorageSync();
}